package com.datastructure.test.maxgap;

import java.util.ArrayList;
import java.util.stream.Collectors;

public class MaxGap {

    public static void main(String[] args) {

    }

    public int maxGap (ArrayList<Integer> nums) {
        // write code here
        int max = Integer.MIN_VALUE;
        ArrayList<Integer> collect = (ArrayList<Integer>)nums.stream().sorted().collect(Collectors.toList());
        for (int i = 0; i < collect.size()-1; i++) {
            max=Math.max(max,collect.get(i+1)-collect.get(i));
        }
        return max;
    }
}
